package com.epalmpay.controller.manage;

import com.alibaba.fastjson.JSONObject;
import com.epalmpay.commom.BaseController;
import com.epalmpay.entity.*;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.agent.IAgentService;
import com.epalmpay.service.shop.IShopService;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.merchantmanage.*;
import com.epalmpay.dto.system.BaseOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.system.UserInDTO;
import com.epalmpay.dto.terminalmanage.GroupPosInDTO;
import com.epalmpay.service.common.IIndustryService;
import com.epalmpay.service.group.IGroupService;
import com.epalmpay.service.management.IUserService;
import com.epalmpay.service.operator.ISysLogService;
import com.epalmpay.util.PropertyCopyUtil;
import com.epalmpay.util.Tools;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value="/manager/group")
public class MerchantManageController extends BaseController {
     
	@Resource  
    private IIndustryService industryService;  

	@Resource  
    private IGroupService merchantService;

	@Resource
	private IShopService shopService;

	@Resource
	private IAgentService agentService;

	@Resource
	private IUserService userService;
	@Resource
	private ISysLogService sysLogService;
	/**
	 * 显示大商户分页列表
	 * 
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	public GroupListOutDTO  listGroup(GroupInDTO groupInDTO,PageDTO pageDTO){
		GroupListOutDTO groupListOutDTO=new GroupListOutDTO();
		try {
			Page page=Tools.pageEmtity(pageDTO);
			//取得行业列表
			groupListOutDTO.setIndustryList(industryService.getFirstLevel());
			//取得销售用户列表
			groupListOutDTO.setDevelopeuserList(userService.getDevelopeUserList());
			
            //查询时取数据			
			if(groupInDTO.getIsReload()){
				//获取大商户列表信息
				List<GroupOutDTO> groupOutDTOList = merchantService.
						getGroupList(groupInDTO.getIndustryID(),groupInDTO.getDevelopeUserID(),
								groupInDTO.getJoinStart(),groupInDTO.getJoinEnd(),groupInDTO.getName(),page);			
				groupListOutDTO.setGroupOutDTOList(groupOutDTOList);
			}
			groupListOutDTO.setPage(page); 
			groupListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupListOutDTO;
		} catch (ApplicationException ae) { 
			groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupListOutDTO;
	}		
		
	/**
	 * 大商户准备增加
	 * 
	 */
	@RequestMapping(value="/goAddGroup")
	@ResponseBody
	public GroupListOutDTO  goAddGroup(GroupInDTO groupInDTO){
		GroupListOutDTO groupListOutDTO=new GroupListOutDTO();
		try {
			//取得行业列表
			groupListOutDTO.setIndustryList(industryService.getFirstLevel());
			//取得销售用户列表
			groupListOutDTO.setDevelopeuserList(userService.getDevelopeUserList());			
			groupListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			groupListOutDTO.setUrl(ROOT_HOME_URL);
			return groupListOutDTO;
		} catch (ApplicationException ae) { 
			groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupListOutDTO;
	}		
	
	/**
	 * 大商户保存
	 * 
	 */
	@RequestMapping(value="/saveGroup")
	@ResponseBody
	public GroupOutDTO  saveGroup(GroupInDTO groupInDTO){
		GroupOutDTO groupOutDTO=new GroupOutDTO();
		try {
            //保存大商户对象
			Long groupId=merchantService.saveGroup(groupInDTO);
			groupOutDTO.setGroupId(groupId); 
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
//			String content ="新增到商户信息";
//			sysLogService.addSysLog(groupInDTO.getLoginId(),groupInDTO.getUserName(),null,content,groupInDTO.getGroupId());
			return groupOutDTO;
		}catch (ApplicationException ae) {
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupOutDTO;
	}		
	
	/*
	* 获取大商户ID和名称接口
	* */
	@RequestMapping(value="/getGroupIdAndName")
	@ResponseBody
	public GroupListOutDTO getGroupIdAndName() {
		GroupListOutDTO groupListOutDTO = new GroupListOutDTO();
		List<GroupOutDTO> groupOutDTOList = null;
		try {
			groupOutDTOList = merchantService.getGroupIdAndName();
			groupListOutDTO.setGroupOutDTOList(groupOutDTOList);
			groupListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
		} catch (Exception e) {
			groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupListOutDTO;
	}


	@RequestMapping(value="/getGroupName")
	@ResponseBody
	public GroupOutDTO getGroupNameById(@RequestBody GroupPosInDTO groupPosInDTO) {
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			//如果渠道ID不为空，表示是渠道登录
			if(groupPosInDTO.getGroupId()!=null){
				groupOutDTO = merchantService.getGroupById(groupPosInDTO.getGroupId());
			}
			//如果代理商ID不为空，表示是代理商登录
			if(groupPosInDTO.getAgentId()!=null){
				groupOutDTO = agentService.getAgentNameById(groupPosInDTO.getAgentId());
			}
			//如果门店ID不为空，表示是门店登录
			if(groupPosInDTO.getShopId()!=null){
				groupOutDTO = shopService.getShopNameById(groupPosInDTO.getShopId());
			}
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
		} catch (Exception e) {
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupOutDTO;

	}
	
	
	@RequestMapping(value="/findByGroupName")
	@ResponseBody
	public GroupOutDTO findInfoByGroupName(GroupInDTO groupInDTO) {
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			groupOutDTO = merchantService.getGroupByNamed(groupInDTO.getMerchantName());
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
		} catch (Exception e) {
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupOutDTO;

	}
	
	
	@RequestMapping(value="/getMerchantName")
	@ResponseBody
	public GroupOutDTO getMerchantName(GroupPosInDTO groupPosInDTO) {
		GroupOutDTO groupOutDTO = new GroupOutDTO(); 
		try {
			groupOutDTO = merchantService.getGroupById(groupPosInDTO.getGroupId());
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
		} catch (Exception e) {
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupOutDTO;

	}
	
	
	
	@RequestMapping(value="/getGroupPhone")
	@ResponseBody
	public GroupOutDTO getGroupPhone(GroupPosInDTO groupPosInDTO) {
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			groupOutDTO = merchantService.getGroupPhone(groupPosInDTO.getGroupId());
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
		} catch (Exception e) {
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupOutDTO;

	}
	
	
	/**
	 * 微信公众号配置保存
	 * 
	 */
	@RequestMapping(value="/saveGroupConfig")
	@ResponseBody
	public GroupWxconfigOutDTO  saveGroupConfig(GroupWxconfigInDTO groupWxconfigInDTO){
		GroupWxconfigOutDTO groupWxconfigOutDTO=new GroupWxconfigOutDTO();
		try {
            //保存大商户对象
			merchantService.saveGroupConfig(groupWxconfigInDTO);
			groupWxconfigOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			
//			String content ="保存微信端大商户信息";
//			sysLogService.addSysLog(groupWxconfigInDTO.getLoginId(),groupWxconfigInDTO.getUserName(),null,content,groupWxconfigInDTO.getGroupId());
			return groupWxconfigOutDTO;
		} catch (ApplicationException ae) { 
			groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupWxconfigOutDTO;
	}	
	
	/**
	 * 微信公众号配置修改
	 * 
	 */
	@RequestMapping(value="/updateGroupConfig")
	@ResponseBody
	public GroupWxconfigOutDTO  updateGroupConfig(GroupWxconfigInDTO groupWxconfigInDTO){
		GroupWxconfigOutDTO groupWxconfigOutDTO=new GroupWxconfigOutDTO();
		try {
            //保存大商户对象
			merchantService.updateGroupConfig(groupWxconfigInDTO);
			groupWxconfigOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			
//			String content ="微信公众号配置修改";
//			sysLogService.addSysLog(groupWxconfigInDTO.getLoginId(),groupWxconfigInDTO.getUserName(),null,content,groupWxconfigInDTO.getGroupId());
//			
			return groupWxconfigOutDTO;
		} catch (ApplicationException ae) { 
			groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupWxconfigOutDTO;
	}	
	
	
	/**
	 * 根据groupId查询微信配置详情
	 * 
	 */
	@RequestMapping(value="/findGroupId")
	@ResponseBody
	public GroupWxconfigOutDTO  findGroupId(GroupWxconfigInDTO groupWxconfigInDTO){
		GroupWxconfigOutDTO groupWxconfigOutDTO=new GroupWxconfigOutDTO();
		try {
			GroupWxconfig groupWxconfig=merchantService.selectGroupWxconfigId(groupWxconfigInDTO.getGroupId());
			if(groupWxconfig!=null){
				PropertyCopyUtil.copyPropertiesExclude(groupWxconfig,groupWxconfigOutDTO);
			}
			groupWxconfigOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupWxconfigOutDTO;
		} catch (ApplicationException ae) { 
			groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupWxconfigOutDTO;
	}	
	
	
	/**
	 * 根据groupId查询商户配置详情
	 * 
	 */
	@RequestMapping(value="/findGroupPayconfigId")
	@ResponseBody
	public GroupPayconfigOutDTO  findGroupPayconfigId(GroupWxconfigInDTO groupWxconfigInDTO){
		GroupPayconfigOutDTO groupWxconfigOutDTO=new GroupPayconfigOutDTO();
		try {
			groupWxconfigOutDTO=merchantService.selectPayconfigId(groupWxconfigInDTO.getGroupId());
			groupWxconfigOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupWxconfigOutDTO;
		} catch (ApplicationException ae) { 
			groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupWxconfigOutDTO;
	}	
	
	/**
	 * 根据groupId修改商户配置详情
	 * 
	 */
	@RequestMapping(value="/updatePayconfig")
	@ResponseBody
	public GroupWxconfigOutDTO  updatePayconfig(GroupPayconfigInDTO groupPayconfigInDTO){
		GroupWxconfigOutDTO groupWxconfigOutDTO=new GroupWxconfigOutDTO();
		try {
            //保存大商户对象
			merchantService.updateGroupPayconfig(groupPayconfigInDTO);
			groupWxconfigOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupWxconfigOutDTO;
		} catch (ApplicationException ae) { 
			groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupWxconfigOutDTO;
	}
	
	/**
	 * 根据groupId查询微信配置详情
	 * 
	 */
	@RequestMapping(value="/findGroupSysConfig")
	@ResponseBody
	public GroupConfigOutDTO  findGroupSysConfig(GroupInDTO groupInDTO){
		GroupConfigOutDTO groupConfigOutDTO=new GroupConfigOutDTO();
		try {
			GroupConfig groupConfig=merchantService.selectGroupSysConfig(groupInDTO.getGroupId());
			if(groupConfig!=null){
				PropertyCopyUtil.copyPropertiesExclude(groupConfig,groupConfigOutDTO);
			}
			groupConfigOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupConfigOutDTO;
		} catch (ApplicationException ae) { 
			groupConfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupConfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupConfigOutDTO;
	}	
	
	
	/**
	 * 根据groupId大商户详情
	 * 
	 */
	@RequestMapping(value="/groupInfo")
	@ResponseBody
	public GroupInfoOutDTO  groupInfo(GroupWxconfigInDTO groupWxconfigInDTO){
		GroupInfoOutDTO groupOutDTO=new GroupInfoOutDTO();
		try {
			Group group=merchantService.selectGroupInfo(groupWxconfigInDTO.getGroupId());
			if(group!=null){
				PropertyCopyUtil.copyPropertiesExclude(group,groupOutDTO);
				groupOutDTO.setUsername(group.getUserbase().getUsername());
				groupOutDTO.setAgentMode(group.getGroupConfig().getAgentMode());
				groupOutDTO.setWxAppid(group.getGroupWxconfig().getWxAppid());
				groupOutDTO.setWxAppsercet(group.getGroupWxconfig().getWxAppsercet());
				groupOutDTO.setWxAppname(group.getGroupWxconfig().getWxAppname());
				groupOutDTO.setWxAppaccount(group.getGroupWxconfig().getWxAppaccount());
				groupOutDTO.setWxQrcodeUrl(group.getGroupWxconfig().getWxQrcodeUrl());
				groupOutDTO.setAccessToken(group.getGroupWxconfig().getAccessToken());
				groupOutDTO.setAeskey(group.getGroupWxconfig().getAeskey());
				groupOutDTO.setWxTxid(group.getGroupWxconfig().getWxTxid());
				groupOutDTO.setWxconfigId(group.getGroupWxconfig().getId());
				groupOutDTO.setUserId(group.getUserbase().getId()); 
			} 
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupOutDTO;
		} catch (ApplicationException ae) { 
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupOutDTO;
	}	
	
	
	/**
	 * 查询模板消息列表
	 * 
	 */
	@RequestMapping(value="/listTemplate")
	@ResponseBody
	public GroupListOutDTO  listTemplate(GroupWxtemplateInDTO groupWxtemplateInDTO){
		GroupListOutDTO groupListOutDTO=new GroupListOutDTO();
		try {
			int type=0;
			if(groupWxtemplateInDTO.getType()!=null){
				type=groupWxtemplateInDTO.getType();
			}
			GroupListOutDTO group=merchantService.wxtemplateList(groupWxtemplateInDTO.getGroupId(),type);
			group.setErrorCode(Rescode.SUCCESS, "处理成功");
			return group;
		} catch (ApplicationException ae) { 
			groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupListOutDTO;
	}
	
	/**
	 * 查询模板消息列表
	 * 
	 */
	@RequestMapping(value="/findTempInfos")
	@ResponseBody
	public GroupWxtemplateListOutDTO  findTempInfos(GroupWxtemplateInDTO groupWxtemplateInDTO){
		GroupWxtemplateListOutDTO groupWxtemplateListOutDTO=new GroupWxtemplateListOutDTO();
		try {
			GroupWxtemplateListOutDTO group=merchantService.findTempInfosList(groupWxtemplateInDTO.getGroupId(),groupWxtemplateInDTO.getType());
			group.setErrorCode(Rescode.SUCCESS, "处理成功");
			return group;
		} catch (ApplicationException ae) { 
			ae.printStackTrace();
			groupWxtemplateListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 groupWxtemplateListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupWxtemplateListOutDTO;
	}
	
	
	/**
	 * 更新模板消息列表
	 * 
	 */
	@RequestMapping(value="/finishSaveTemplates")
	@ResponseBody
	public GroupWxtemplateListOutDTO  finishSaveTemplate(@RequestBody List<GroupWxtemplateInDTO>groupWxtemplateInsDTO){
		GroupWxtemplateListOutDTO groupWxtemplateListOutDTO=new GroupWxtemplateListOutDTO();
		try {
			System.out.println("finishSaveTemplate.."+JSONObject.toJSONString(groupWxtemplateInsDTO));
			GroupWxtemplateListOutDTO group=merchantService.finishSaveTemplates(groupWxtemplateInsDTO);
			group.setErrorCode(Rescode.SUCCESS, "处理成功");
			return group;
		} catch (ApplicationException ae) { 
			groupWxtemplateListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 groupWxtemplateListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupWxtemplateListOutDTO;
	}
	
	/**
	 * 保存模板信息
	 * 
	 */
	@RequestMapping(value="/saveTemplate")
	@ResponseBody
	public GroupWxconfigOutDTO  saveTemplate(GroupWxtemplateInDTO groupWxtemplateInDTO){
		GroupWxconfigOutDTO groupWxconfigOutDTO=new GroupWxconfigOutDTO();
		try {
			merchantService.saveWxtemplate(groupWxtemplateInDTO);
			groupWxconfigOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupWxconfigOutDTO;
		} catch (ApplicationException ae) { 
			ae.printStackTrace();
			groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupWxconfigOutDTO;
	}	
	
	

	/**
	 * 根据id查询模板详情
	 * 
	 */
	@RequestMapping(value="/findTemplate")
	@ResponseBody
	public GroupWxtemplateOutDTO  findTemplate(GroupWxtemplateInDTO groupWxtemplateInDTO){
		GroupWxtemplateOutDTO groupWxtemplateOutDTO=new GroupWxtemplateOutDTO();
		try {
			GroupWxtemplateOutDTO groupWxtemplate=merchantService.findTemplate(groupWxtemplateInDTO);
			groupWxtemplate.setErrorCode(Rescode.SUCCESS, "处理成功");
			return groupWxtemplate;
		} catch (ApplicationException ae) { 
			ae.printStackTrace();
			groupWxtemplateOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 groupWxtemplateOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupWxtemplateOutDTO;
	}	
	
	
	
	/**
	 * 删除模板信息
	 * 
	 */
	@RequestMapping(value="/deleteTemplate")
	@ResponseBody
	public GroupWxtemplateOutDTO  deleteTemplate(GroupWxtemplateInDTO groupWxtemplateInDTO){
		GroupWxtemplateOutDTO groupWxtemplateOutDTO=new GroupWxtemplateOutDTO();
		try {
			merchantService.deleteWxtemplate(groupWxtemplateInDTO);
			groupWxtemplateOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
		
	} catch (ApplicationException ae) { 
		ae.printStackTrace();
		groupWxtemplateOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
	}
	 catch (Exception e) { 
		 e.printStackTrace();
		 groupWxtemplateOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
	}
		return groupWxtemplateOutDTO;
	}	
	
	
	/**
	 *重置密码
	 * 
	 */
	@RequestMapping(value="/resetPassword")
	@ResponseBody
	public GroupWxconfigOutDTO  resetPassword(UserInDTO userInDTO){
		GroupWxconfigOutDTO groupWxconfigOutDTO=new GroupWxconfigOutDTO();
		try {
			Boolean flag=merchantService.resetPassword(userInDTO);
			if(flag){
				groupWxconfigOutDTO.setErrorCode(Rescode.SUCCESS, "密码重置成功成功");
			}else{
				groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "密码重置失败");
			}
	} catch (ApplicationException ae) { 
		ae.printStackTrace();
		groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
	}
	 catch (Exception e) { 
		 e.printStackTrace();
		 groupWxconfigOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
	}
		return groupWxconfigOutDTO;
	}	
	
	
	/**
	 *重置修改
	 * 
	 */
	@RequestMapping(value="/updatePassword")
	@ResponseBody
	public BaseOutDTO  updatePassword(UserInDTO userInDTO){
		BaseOutDTO baseOutDTO=null;
		try {
		    baseOutDTO=merchantService.updatePassword(userInDTO);
		} 
		 catch (Exception e) { 
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}

	/**
	 *重置修改
	 *
	 */
	@RequestMapping(value="/hasPayGroupCode")
	@ResponseBody
	public GroupOutDTO hasPayGroupCode(GroupInDTO groupInDTO){
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			 merchantService.hasPayGroupCode(groupInDTO);
		} catch (ApplicationException ae) { 
			ae.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupOutDTO;
	}

	
	/**
	 * 查询微信菜单列表
	 * 
	 */
	@RequestMapping(value="/listWxmenu")
	@ResponseBody
	public GroupListOutDTO  listWxmenu(GroupWxmenuInfoInDTO groupWxmenuInfoInDTO){
		GroupListOutDTO groupListOutDTO=new GroupListOutDTO();
		try {
			GroupListOutDTO group=merchantService.wxMenuList(groupWxmenuInfoInDTO);
			group.setErrorCode(Rescode.SUCCESS, "处理成功");
			return group;
		} catch (ApplicationException ae) { 
			ae.printStackTrace();
			groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 groupListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupListOutDTO;
	}
	
	/**
	 * 保存微信菜单信息
	 * 
	 */
	@RequestMapping(value="/saveWxmenu")
	@ResponseBody
	public BaseOutDTO  saveWxmenu(GroupWxmenuInfoInDTO groupWxmenuInfoInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			merchantService.saveWxMenu(groupWxmenuInfoInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) { 
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}

	/**
	 * 删除微信菜单信息
	 * 
	 */
	@RequestMapping(value="/deleteWxmenu")
	@ResponseBody
	public BaseOutDTO  deleteWxmenu(GroupWxmenuInfoInDTO groupWxmenuInfoInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			baseOutDTO=merchantService.deleteWxMenu(groupWxmenuInfoInDTO);
		} 
		 catch (Exception e) { 
			 e.printStackTrace();
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}	
	
	/**
	 * 保存微信菜单信息
	 * 
	 */
	@RequestMapping(value="/updateWxmenu")
	@ResponseBody
	public BaseOutDTO  updateWxmenu(GroupWxmenuInfoInDTO groupWxmenuInfoInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			merchantService.updateWxMenu(groupWxmenuInfoInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) { 
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}

	
	/**
	 * 同步微信菜单信息
	 * 
	 */
	@RequestMapping(value="/synchronizeWxmenu")
	@ResponseBody
	public BaseOutDTO  synchronizeWxmenu(GroupWxmenuInfoInDTO groupWxmenuInfoInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			merchantService.synchronizeWxMenu(groupWxmenuInfoInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) { 
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		 catch (Exception e) { 
			 e.printStackTrace();
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}
	
	/**
	 * 根据groupId查询微信配置详情
	 * 
	 */
	@RequestMapping(value="/findWxmenuId")
	@ResponseBody
	public GroupWxmenuInfoOutDTO  findWxmenuId(GroupWxmenuInfoInDTO groupWxmenuInfoInDTO){
		GroupWxmenuInfoOutDTO groupWxmenuInfoOutDTO=new GroupWxmenuInfoOutDTO();
		try {
			GroupWxmenuInfoOutDTO groupWxmenuList=merchantService.findWxmenuId(groupWxmenuInfoInDTO);
			return groupWxmenuList;
		} catch (ApplicationException ae) { 
			groupWxmenuInfoOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupWxmenuInfoOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupWxmenuInfoOutDTO;
	}
	
	
	
	/**
	 * 根据groupId和父级查询微信配置详情
	 * 
	 */
	@RequestMapping(value="/findParentWxmenuId")
	@ResponseBody
	public GroupWxmenuInfoOutDTO  findParentWxmenuId(GroupWxmenuInfoInDTO groupWxmenuInfoInDTO){
		GroupWxmenuInfoOutDTO groupWxmenuInfoOutDTO=new GroupWxmenuInfoOutDTO();
		try {
			GroupWxmenuInfoOutDTO groupWxmenuList=merchantService.findParentWxmenuId(groupWxmenuInfoInDTO);
			return groupWxmenuList;
		} catch (ApplicationException ae) { 
			groupWxmenuInfoOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 groupWxmenuInfoOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupWxmenuInfoOutDTO;
	}


	/**
	 * 根据groupId去查询大商户和代理商的协议
	 *
	 */
	@RequestMapping(value="/queryGroupProtocol")
	@ResponseBody
	public GroupOutDTO  queryGroupProtocol(GroupInDTO groupInDTO){
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			groupOutDTO=merchantService.queryGroupProtocol(groupInDTO);
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
			return groupOutDTO;
		} catch (ApplicationException ae) {
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
			ae.printStackTrace();
		}
		catch (Exception e) {
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return groupOutDTO;
	}

	/**
	 *保存协议
	 *
	 */
	@RequestMapping(value="/saveGroupProtocol")
	@ResponseBody
	public GroupOutDTO saveGroupProtocol(GroupInDTO groupInDTO){
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			merchantService.saveGroupProtocol(groupInDTO);
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");
		} catch (ApplicationException ae) {
			ae.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		catch (Exception e) {
			e.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupOutDTO;
	}

	/**
	 *根据groupid获取下属门店的行业类型
	 *
	 */
	@RequestMapping(value="/grouptrade")
	@ResponseBody
	public List getGroupTrade(){
		Map param = new HashMap();
		param.put("groupId", Long.parseLong(getRequest().getParameter("groupid")));
		return merchantService.getGroupTrade(param);
	}

	/**
	 *根据groupid和行业类型获取下属门店
	 *
	 */
	@RequestMapping(value="/grouptradeshop")
	@ResponseBody
	public List getGroupTradeShop(){
		Map param = new HashMap();
		param.put("groupId", getRequest().getParameter("groupid"));
		param.put("industry", getRequest().getParameter("industry"));
		return merchantService.getGroupTradeShop(param);
	}



	@RequestMapping(value="/editGroup")
	@ResponseBody
	public GroupOutDTO editGroup(GroupInDTO groupInDTO){
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			merchantService.editGroup(groupInDTO);
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");
		} catch (ApplicationException ae) {
			ae.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		catch (Exception e) {
			e.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupOutDTO;

	}

	@RequestMapping(value="/saveGroupProfile")
	@ResponseBody
	public BaseOutDTO saveGroupProfile(GroupProfileInDTO groupProfileInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			Map param = new HashMap();
			param.put("groupid", groupProfileInDTO.getGroupId());
			param.put("extendprofilerate", groupProfileInDTO.getExtendprofilerate());
			param.put("zhangfuprofilerate", groupProfileInDTO.getZhangfuprofilerate());
			param.put("operateprofilerate", groupProfileInDTO.getOperateprofilerate());
			param.put("platformprofilerate", groupProfileInDTO.getPlatformprofilerate());
			param.put("operatetype", groupProfileInDTO.getOperatetype());
			merchantService.saveGroupProfile(param);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/deleteGroupProfile")
	@ResponseBody
	public BaseOutDTO deleteGroupProfile(Map param){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			merchantService.deleteGroupProfile(param);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/selectGroupProfileByGroupId")
	@ResponseBody
	public Map selectGroupProfileByGroupId(Map param){
		Map result = new HashMap();
		try {
			GroupProfile groupProfile = merchantService.selectProfileByGroupid(Long.parseLong(param.get("groupid").toString()));
			result.put("groupProfile", groupProfile);
			result.put("status", "0000");
		} catch (Exception e) {
			e.printStackTrace();
			result.put("status", "99");
		}
		return result;
	}

	@RequestMapping(value="/updateGroupProfileById")
	@ResponseBody
	public BaseOutDTO updateGroupProfileById(Map param){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			merchantService.updateGroupProfileById(param);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return baseOutDTO;
	}


	@RequestMapping(value="/goEditRate")
	@ResponseBody
	public GroupOutDTO goEditRate(GroupInDTO groupInDTO){
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			groupOutDTO =merchantService.goEditRate(groupInDTO);
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");
		} catch (ApplicationException ae) {
			ae.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		catch (Exception e) {
			e.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupOutDTO;

	}

	@RequestMapping(value="/editGroupInfo")
	@ResponseBody
	public GroupOutDTO editGroupInfo(GroupInDTO groupInDTO){
		GroupOutDTO groupOutDTO = new GroupOutDTO();
		try {
			merchantService.editGroupInfo(groupInDTO);
			groupOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");
		} catch (ApplicationException ae) {
			ae.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.getMessage());
		}
		catch (Exception e) {
			e.printStackTrace();
			groupOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
		}
		return groupOutDTO;

	}

}
